package com.lwbldy.common.plugins.logging.controller;

import com.lwbldy.common.tools.R;
import com.lwbldy.common.tools.PageUtils;
import com.lwbldy.common.tools.StringUtils;

import com.lwbldy.common.plugins.logging.domain.SysLogging;
import com.lwbldy.common.plugins.logging.service.SysLoggingService;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 *  Controller
 * @author lwb
 * @email lwbldy@163.com
 * @date 2022-03-11 15:41:57
 */
@Controller
@Api(tags = "")
@RequestMapping("/logging/syslogging")
public class SysLoggingController {

    /**
     * Describe: 基础路径
     * */
    private static String MODULE_PATH = "logging/syslogging/";


    @Autowired
    private SysLoggingService sysLoggingService;

    @ApiOperation(value="获取列表视图")
    @GetMapping("/main")
    public String main(){
        return MODULE_PATH + "main";
    }


    @ApiOperation(value = "分页查询")
    @PostMapping("/list")
    @ResponseBody
    public R list(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "limit", defaultValue = "15") Integer limit){
        PageHelper.startPage(page, limit);
        Map<String,Object> primaryMap = new HashMap<>();
        List<SysLogging> brandList = sysLoggingService.queryList(primaryMap);
        return PageUtils.restPage(brandList);
    }


    @ApiOperation(value = "获取新增视图")
    @GetMapping("add")
    public String add(ModelMap model){
        return MODULE_PATH + "add";
    }

    @ApiOperation(value = "保存")
    @PostMapping("save")
    @ResponseBody
    public R save(@RequestBody SysLogging sysLogging){
        return R.resultRow(sysLoggingService.save(sysLogging));
    }


    @ApiOperation(value = "获取修改视图")
    @GetMapping("edit")
    public String edit(ModelMap model, Long id){
        model.put("sysLogging",sysLoggingService.queryObject(id));
        return MODULE_PATH + "edit";
    }

    @ApiOperation(value = "修改信息")
    @PutMapping("update")
    @ResponseBody
    public R update(@RequestBody SysLogging sysLogging){
        return R.resultRow(sysLoggingService.update(sysLogging));
    }

    @ApiOperation(value = "根据ID删除")
    @DeleteMapping("remove/{id}")
    @ResponseBody
    public R remove(@PathVariable Long id){
        int result = sysLoggingService.delete(id);
        return R.resultRow(result);
    }

    @DeleteMapping("removeBatch/{ids}")
    @ApiOperation(value="批量删除数据")
    @ResponseBody
    public R removeBatch(@PathVariable String ids){
        int result = sysLoggingService.deleteBatch(StringUtils.StringIdsToArr(ids));
        return R.resultRow(result);
    }

}
